﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for cls_tb_GROUPCHINHANH_XUATHOADON
/// </summary>
public class cls_tb_GROUPCHINHANH_XUATHOADON
{
	public cls_tb_GROUPCHINHANH_XUATHOADON()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    #region select
    public static DataTable GetByF_MACN(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        SqlParameter[] para = new SqlParameter[1];

        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("tb_GROUPCHINHANH_XUATHOADON_GetF_MACN", para);
        }
        catch { }
        return dt;
    }
    public static int getID_GROUPbyF_MACN(string F_MACN)
    {
        int rs = 0;
        DataTable dt = new DataTable();
        dt = GetByF_MACN(F_MACN);
        if (dt.Rows.Count > 0)
        {
            try {
                rs = int.Parse(dt.Rows[0]["ID_GROUP"].ToString());
            }
            catch { }
        }
        return rs;
    }
    public static DataTable GetAll()
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        //SqlParameter[] para = new SqlParameter[1];

        //para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("tb_GROUPCHINHANH_XUATHOADON_GetAll", null);
        }
        catch { }
        return dt;
    }
    #endregion
    #region Update
    public static string Update(int ID,int ID_GROUP, string F_MACN)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { ID, ID_GROUP, F_MACN };
        string[] parameters = { "@ID", "@ID_GROUP", "@F_MACN" };

        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }

        try
        {
            connect.ExecuteQuery("tb_GROUPCHINHANH_XUATHOADON_Update", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    #endregion
    public static string Insert(int ID_GROUP, string F_MACN)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { ID_GROUP, F_MACN };
        string[] parameters = { "@ID_GROUP", "@F_MACN" };

        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }

        try
        {
            connect.ExecuteQuery("tb_GROUPCHINHANH_XUATHOADON_Insert", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    public static string Delete(int ID)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { ID };
        string[] parameters = { "@ID" };

        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }

        try
        {
            connect.ExecuteQuery("tb_GROUPCHINHANH_XUATHOADON_Delete", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
}